local diaoling = fk.CreateSkill {

  name = "joy__diaoling",

  tags = {  },

}



diaoling:addEffect("active", {
  name = "joy__diaoling",
  anim_type = "control",
  min_card_num = 1,
  target_num = 1,
  prompt = "#joy__diaoling",
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select):getMark("@@joy__mubing-inhand") > 0
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local room = player.room
    local player = effect.from
    local target = effect.tos[1]
    local cards = effect.cards
    room:obtainCard(target,cards,false,fk.ReasonGive,player.id,diaoling.name)
    if player.dead then return end
    local n = #cards - 1
    local  gets = {}
    for _, cid in ipairs(cards) do
      local c =  Fk:getCardById(cid)
      if #gets == 0 then
        table.insertIfNeed(gets,cid)
      else
        local gets2 = table.simpleClone(gets)
        for k, cid2 in pairs(gets2) do
          local c2 = Fk:getCardById(cid2)
          if c.number < c2.number then
            table.insert(gets,k,cid)
          elseif c.number == c2.number then
            return 
          end
        end
        if not table.contains(gets,cid) then
          table.insert(gets,#gets + 1,cid)
        end
      end
    end
    if #gets > 0 then
      local num 
      for k, cid in ipairs(gets) do
        if k == 1 then
          num = Fk:getCardById(cid).number
        else
          num = num + 1
          if Fk:getCardById(cid).number ~= num then
            return
          end
        end
      end
    end
    if  n > 0 and not player.dead then
      local targets = room:askForChoosePlayers(player,table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p:isNude() end), Util.IdMapper),1,n,"#joy__diaoling-get:::"..n,diaoling.name,true)
      if #targets > 0 then
        for _, pid in ipairs(targets) do
          if player.dead then return end
          local p = room:getPlayerById(pid)
          local card = room:askForCardChosen(player,p,"he",diaoling.name)
          if card ~= nil then
            room:obtainCard(player,card,false,fk.ReasonPrey)
          end
        end
      end
    end
  end,
})

return diaoling